<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*, loginmysql.*"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%!int unidad; 
String icon;%>
<%
	//session = request.getSession(false);
	if (session == null || session.getAttribute("loggedIn") == null) {//logoogle
		//not logged
%><a href="FormLogin.jsp">Inicie Sesion</a>
<%
	} else if ((Integer) session.getAttribute("priv") == 1) {
%><a href="FormLogin.jsp">No tiene los privilegios necesarios</a>
<%
	} else {
		//logged
%>
<head>
<link rel="stylesheet" href="css/metro-bootstrap.css">
<link rel="stylesheet" href="css/modalcss.css">
<link href="css/iconFont.css" rel="stylesheet">
<script src="js/jquery-1.11.1.js"></script>
<script src="js/modal.js"></script>
<script src="js/hist.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Panel de Control</title>

<jsp:include page="Nav.html"></jsp:include>

<h1 style="text-align: center">Historial</h1>

</head>
<body class="metro">
	<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
		url="jdbc:mysql://localhost/cot" user="root" password="Beyer9499" />
	<%
	if(request.getParameter("unidad")==null){
			
	}else{
		//unidad= request.getParameter("unidad");
		System.out.println(request.getParameter("unidad"));
		unidad = Integer.parseInt(request.getParameter("unidad"));
	}
	%>
		

	<sql:query dataSource="${snapshot}" var="result">
SELECT Uid, HoraControl, localidad.info, FuncId, Fecha, nombre, apellido, FormId, form.lid, (select count(yn) from itemdata where yn=0 and Fid=form.FormId ) as problemas from form, funcionarios, localidad where Uid=<%=unidad %> and FuncId=id and form.lid=localidad.lid order by FormId desc;
</sql:query>
<form method=POST action="Historial.jsp" id="formSalida">
	<div id='centered'>
		<span>Unidad: </span> <select name="unidad">
			<%	MysqlLogin.connect();
				ArrayList<String> unidades = null;
					unidades = MysqlLogin.getUnidades();
				MysqlLogin.disconnect();	
					for (String unobject : unidades) {
						//System.out.println(object);
			%><option value="<%=unobject%>"><%=unobject%></option>
			<%
				}
			%>
		</select>
		<input type=SUBMIT value="Buscar"/>
	</div>
	</form>
	<table class="table hovered bordered" id="table">
		<thead>
			<tr>
				<th class="text-left">Detalle</th>
				<th class="text-left">Unidad</th>
				<th class="text-left" style='width:200px' >Fecha de Inspecci&oacute;n</th>
				<th class="text-left">Hora Inspecci&oacute;n</th>
				<th class="text-left">Funcionario</th>
				<th class="text-left">Lugar</th>
				<th class="text-left">Problemas</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach var="row" items="${result.rows}">
			<c:choose>
					<c:when test="${row.problemas>0}"><%icon="<i class='icon-cancel-2 fg-red'></i>";%></c:when>
					<c:when test="${row.problemas==0}"><%icon="<i class='icon-checkmark fg-green'></i>";%></c:when>
				</c:choose>
				<tr data-row="" class="${row.FormId}">
					<td><button class="${row.FormId}" data-info="">></button></td>
					<td><c:out value="${row.Uid}" /></td>
					<td><c:out value="${row.Fecha}" /></td>
					<td><c:out value="${row.HoraControl}" /></td>
					<td><c:out value="${row.nombre} "/><c:out value="${row.apellido}" /></td>
					<td><c:out value="${row.info}"/></td>
					<td><%=icon%></td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
</body>
</html>
<%
	}
%>